import cv2
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
from modelscope.outputs import OutputKeys
import os

# 获取当前脚本所在目录
current_dir = os.path.dirname(os.path.abspath(__file__))
output_path = os.path.join(current_dir, 'result.png')

portrait_enhancement = pipeline(Tasks.image_portrait_enhancement, model='iic/cv_gpen_image-portrait-enhancement-hires')
result = portrait_enhancement('https://pic.slas.cc/2025/20250420%E4%B8%8B%E5%8D%8851701_D2rbHK_%E7%8E%8B%E8%AF%97%E6%B6%B5_2025-04-20_17-10-46.jpeg')
cv2.imwrite(output_path, result[OutputKeys.OUTPUT_IMG])